<?php

/*

  Action	$3

  +1 Card; +1 Action
  Name a card, then reveal the top card of your deck.
  If it is the named card, put it in your hand.

 */

class WishingWell extends Card implements iAction, iKingdom, iIntrigue {

    public function __construct() {
        parent::__construct("Wishing Well", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "Name a card, then reveal the top card of your deck.  If it is the named card, put it in your hand.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action and draw " . nicePrint($drawed_cards), "gets +1 action and draws " . sizeof($drawed_cards) . " cards");

        $tempCard = $game->peekCardFromDrawDeck();
        if ($tempCard != null) {
            $board_cards = $game->getAllBoardCards();
            ksort($board_cards);
            
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $board_cards, 1, 1, null, "Wish for a card");
            $card = n2c($output[0]);
            ScreenDisplay::addScreenMessage($game, true, "wish for " . nicePrint($card), "wishes for " . ScreenDisplay::$LMSG);
            $wish_card = $game->peekCardFromDrawDeck();
            if ($wish_card->getKey() == $card->getKey()) {
                $game->drawCards(1);
                ScreenDisplay::addScreenMessage($game, false, " and you get it! ", " and  gets it!");
            } else {
                ScreenDisplay::addScreenMessage($game, false, " but reveal " . nicePrint($wish_card) . ", what a shame", " but reveals " . ScreenDisplay::$LMSG . ", what a failure");
            }
        }
        $game->cardActionFinished();
        return true;
    }

}

?>